package jnpf.service;


import jnpf.mapper.SessionMapper;
import jnpf.model.school.vo.SchoolVO;
import jnpf.model.session.vo.SessionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Calendar;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class SessionService {

    @Autowired
    private SessionMapper sessionMapper;

    //* 查找学校
    public List<SessionVO> listSession(String schoolId, Integer actived) {
        List<SessionVO> sessionVO = sessionMapper.listSession(schoolId, actived);
        sessionVO.stream().map(listVO -> {
            if (listVO.getChargerId() == null) {
                listVO.setChargerName("未设置");
            }
            Calendar cal = Calendar.getInstance();
            int month = cal.get(Calendar.MONTH) + 1;
            int year = cal.get(Calendar.YEAR);
            if (month >= 7) {
                year = year + 1;
            }
            int sessionNo = 0;
            if (year - Integer.valueOf(listVO.getName()).intValue() < 0) {
                sessionNo = -1;
            } else {
                sessionNo = year - Integer.valueOf(listVO.getName()).intValue();
            }
            switch (sessionNo) {
                case -1:
                    listVO.setGradeShow(listVO.getName() + "届/未入学");
                    break;
                case 0:
                    listVO.setGradeShow(listVO.getName() + "届/新生");
                    break;
                case 1:
                    listVO.setGradeShow(listVO.getName() + "届/一年级");
                    break;
                case 2:
                    listVO.setGradeShow(listVO.getName() + "届/二年级");
                    break;
                case 3:
                    listVO.setGradeShow(listVO.getName() + "届/三年级");
                    break;
                case 4:
                    listVO.setGradeShow(listVO.getName() + "届/四年级");
                    break;
                case 5:
                    listVO.setGradeShow(listVO.getName() + "届/五年级");
                    break;
                case 6:
                    listVO.setGradeShow(listVO.getName() + "届/六年级");
                    break;
                default:
                    listVO.setGradeShow(listVO.getName() + "届/毕业");
                    break;
            }
            listVO.setGradeShowWithClazzCount(listVO.getGradeShow() + '(' + listVO.getClazzCount() + ')');
            return listVO;
        }).collect(Collectors.toList());
        return sessionVO;
    }
}

